package com.emex.app.stuff.gui.model;

import com.emex.app.shared.data.Car;
import com.emex.app.shared.data.Client;
import com.emex.app.stuff.provider.CarDataProvider;
import java.util.List;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;

/**
 *
 * @author Sergey Karavaev
 */
public class CarComboBoxModel extends AbstractListModel implements ComboBoxModel {
    
     /**
     * Currently selected car object.
     */
    private Car selection;
    /**
     * Array of cars - needed to implement ComboBoxModel functionality.
     */
    private List<Car> cars;


    public CarComboBoxModel(Client client) {
        cars = CarDataProvider.getInstance().getAllCarsByClientId(client.getId());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setSelectedItem(Object anItem) {
        selection = (Car) anItem;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object getSelectedItem() {
        return selection;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getSize() {
        return cars.size();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object getElementAt(int index) {
        return cars.get(index);
    }
}
